package com.yuyu.commons.security;

import java.util.Objects;

/**
 * @author
 * @version 1.0
 * @description: 登录上下文
 * @date 2022/8/3 15:44
 */
public final class LoginContext {

    private final static ThreadLocal<LoginUser> loginThreadLocal=new ThreadLocal<>();

    private LoginContext(){}

    public static LoginUser getUser(){
      return  loginThreadLocal.get();
    }

    public static void setUser(LoginUser loginUser){
        if (Objects.nonNull(loginUser)) {
            loginThreadLocal.set(loginUser);
        }
    }

    public static void clear(){
        loginThreadLocal.remove();
    }

}
